package com.xyh.transaction.controller;

import com.github.pagehelper.PageInfo;
import com.xyh.transaction.entity.dto.RotateDto;
import com.xyh.transaction.entity.vo.RotateVo;
import com.xyh.transaction.entity.vo.CategoryVo;
import com.xyh.transaction.entity.vo.GoodsVo;
import com.xyh.transaction.entity.vo.HotVo;
import com.xyh.transaction.response.ResponseResult;
import com.xyh.transaction.service.CategoryService;
import com.xyh.transaction.service.GoodsService;
import com.xyh.transaction.service.HotService;
import com.xyh.transaction.service.ImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "首页管理")
@RestController
@RequestMapping("home")
public class HomeController {

    @Autowired
    private CategoryService categoryService;

    @Autowired
    private ImageService imageService;

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private HotService hotService;

    @ApiOperation(value = "首页分类", notes = "首页分类列表")
    @GetMapping("/category/head")
    public ResponseResult<List<CategoryVo>> head() {
        List<CategoryVo> categoryList = categoryService.getHeadCategoryList();

        return ResponseResult.success("操作成功", categoryList);
    }

    @ApiOperation(value = "轮播图", notes = "返回轮播图列表")
    @GetMapping("banner")
    public ResponseResult<PageInfo<RotateVo>> bannerList(RotateDto bannerDto) {
        PageInfo<RotateVo> bannerList = imageService.getRotateList(bannerDto);
        return ResponseResult.success("查询成功！", bannerList);
    }

    @ApiOperation(value = "首页急售", notes = "返回首页急售模块商品列表")
    @GetMapping("urgent")
    public ResponseResult<List<GoodsVo>> newList() {
        List<GoodsVo> urgentGoodsList = goodsService.getUrgentGoodsList();
        return ResponseResult.success("查询成功！", urgentGoodsList);
    }

    @ApiOperation(value = "首页热门推荐", notes = "返回热门推荐类型")
    @GetMapping("hot")
    public ResponseResult<List<HotVo>> hotList() {
        List<HotVo> hotList = hotService.getHotList();
        return ResponseResult.success("查询成功！", hotList);
    }

    @ApiOperation(value = "首页产品展示",notes = "返回首页商品展示列表")
    @GetMapping("goods")
    public ResponseResult<List<CategoryVo>> goodsList(){
        List<CategoryVo> homeGoodsList = categoryService.getHeadCategoryList();
        return ResponseResult.success("查询成功！",homeGoodsList);
    }


}
